﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Vote.Models;


namespace Dal
{
    /// <summary>
    /// 操作底层
    /// </summary>
    /// <typeparam name="T"></typeparam>
    interface IDalCommon
    {
        /// <summary>
        /// 新增实体表
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        int AddNewEntity<T>(string tableName,T obj) where T : class;


        /// <summary>
        /// 获取数量
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        int GetCountBySQL(string tableName, string sql);

        /// <summary>
        /// 通过id删除某一条信息
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        int DeleteEntity<T>(string tableName, long id) where T : class;
       

        /// <summary>
        /// 删除实体类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="sql"></param>
        int DeleteEntityBySql(string tableName, string sql);


        /// <summary>
        /// 修改实体类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="tableName"></param>
        int UpdateEntity<T>(string tableName,T obj) where T : class;

        /// <summary>
        /// 更新实体类
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="sql"></param>
        int UpdateEntityBySql(string tableName, string sql);

        /// <summary>
        /// 查询实体类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        T SelectEntity<T>(string tableName, long id) where T : class;

        /// <summary>
        /// 查询实体类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        List<T> SelectEntityBySql<T>(string tableName, string sql) where T : class;

        /// <summary>
        /// 获取用户自定义字段
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="sql">只能获取一个字段,这个字段可以返回单个值也可以返回一列值</param>
        /// <param name="type">基本类型 如 string int long bool decimal</param>
        /// <param name="isList">是否返回列表 true:返回一列  false:单个值</param>
        /// <returns></returns>
         Object SelectSingleValueBySql(string tableName, string sql,string type="string",bool isList=false);
        
        /// <summary>
        /// 分页获取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="conditionFiledValue"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderByFiled"></param>
        /// <param name="desc"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        List<T> SelectEntityInfoByQueryWithPager<T>(string tableName, Dictionary<string, string> conditionFiledValue, int currentPage, int pageSize, string orderByFiled, bool desc, out int totalPage) where T : new();

    }
}
